<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateDictTables extends Migration
{
    public $tablePrefix = 'kx_';

    public function __construct() {
        $tablePrefix = \Config::get('site-tables.tablePrefix');
        if ($tablePrefix) {
            $this->tablePrefix = $tablePrefix;
        }
    }

    public function getTableName($tableName = ''){
        return $this->tablePrefix . \Config::get('site-tables.tableName.' . $tableName);
    }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (! Schema::hasTable($this->getTableName('dict_words'))) {
            Schema::create( $this->getTableName('dict_words'), function (Blueprint $table) {
                $table->increments('wd_id');
                $table->string('wd_category')->default('');
                $table->string('wd_first_letter', 1)->default('');
                $table->string('wd_root')->default('');
                $table->string('wd_prefix')->default('');
                $table->string('wd_suffix')->default('');
                $table->string('wd_en')->default('');
                $table->string('wd_cn')->default('');
                $table->string('wd_basic_cn')->default('');
                $table->string('wd_basic_en')->default('');
                $table->string('symbol')->default('');
                $table->string('phonetic_uk')->default('');
                $table->string('phonetic_usa')->default('');
                $table->tinyInteger('collins_level')->default('0')->comment('柯林斯词频分级:0,1,2,3,4,5');
                $table->string('updated_by', 100)->default('');
                $table->dateTime('updated_at');
                $table->string('remark')->default('')->comment('Notice or Comment');
                $table->tinyInteger('status')->default(1)->comment('[Status]1:default,0:hide,-1:delete');
            });
        }
 
        if (! Schema::hasTable($this->getTableName('dict_roots'))) {
            Schema::create( $this->getTableName('dict_roots'), function (Blueprint $table) {
                $table->increments('root_id');
                $table->string('root_first_letter')->default('');
                $table->tinyInteger('root_type')->default(0);
                $table->string('root_name')->default('');
                $table->string('root_detail')->default('');
                $table->string('root_example')->default('');
                $table->string('root_explain')->default('');
                $table->string('updated_by', 100)->default('');
                $table->dateTime('updated_at');
                $table->string('remark')->default('')->comment('Notice or Comment');
                $table->tinyInteger('status')->default(1)->comment('[Status]1:default,0:hide,-1:delete');
            });
        }

        if (! Schema::hasTable($this->getTableName('dict_sentences'))) {
            Schema::create( $this->getTableName('dict_sentences'), function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->text('content');
                $table->text('explanation');
                $table->string('source_name', 255)->default('none');
                $table->string('source_link', 255)->default('');
                $table->dateTime('created_at');
                $table->dateTime('updated_at');
                $table->string('created_by', 100)->default('');
                $table->string('updated_by', 100)->default('');
                $table->string('remark')->default('')->comment('Notice or Comment');
                $table->tinyInteger('status')->default(1)->comment('[Status]1:default,0:hide,-1:delete');
            });
        }

        if (! Schema::hasTable($this->getTableName('dict_logs'))) {
            Schema::create( $this->getTableName('dict_logs'), function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->tinyInteger('type')->default(1)->comment('[LogTypes]0:default,1:words,2:roots,3:sentences');
                $table->string('user_id')->default(0);
                $table->string('user_name')->default('');
                $table->string('content')->default('');
                $table->string('ip_address')->default('');
                $table->string('user_agent')->default('');
                $table->string('created_by', 100)->default('');
                $table->dateTime('created_at');
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
